import 'package:get/get.dart';
import 'package:xin_nuo_pda/base/BaseController.dart';
import 'package:xin_nuo_pda/bean/lot_entity.dart';
import 'package:xin_nuo_pda/http/api/lot_api.dart';

import '../../bean/bin_info_entity.dart';
import '../../routes/Routes.dart';
import 'PassEndWorkState.dart';

class PassEndWorkController extends BaseController {
  final PassEndWorkState state = PassEndWorkState();

  updateGroupValue(var value) {
    state.groupValue = value;
    update([state.passEndWorkBinSelectId]);
  }

  getLotInfo(String lot) async{
    Map<String, dynamic> params = {'LOTID': lot};
    var result = await LotApi.lotInfo(canelToken, params: params);
    if (result.ok) {
      state.lotEntity = result.data;
      List<LotEntity> lotList = [];
      lotList.add(state.lotEntity ?? LotEntity());
      Map<String, dynamic> map = {'ACTIONTYPE': 'SelectBinData','EQPID' : state.lotEntity?.eQUIPMENTID,'LOTLIST' : lotList};
      var bindata = await LotApi.getSelectorBin(canelToken,params: map);
      if(bindata.ok){
          state.binDataEntity = bindata.data;
          if(bindata.data!.LOTBINDATALIST!.isNotEmpty){
            state.binData = bindata.data?.LOTBINDATALIST;
          }else{
            Get.snackbar('提示', '服务器返回BIN数据为空！');
          }
          update([state.passEndWorkId]);
      }

      }
    }

  void next() {
    BinInfo? entity;
    state.binData?.forEach((element) {
      if(element.BINNAME == 'BIN1'){
          entity = element;
      }
    });

    if(entity == null){
      Get.snackbar('提示', '未找到BIN1数据');
      return;
    }
    Get.toNamed(Routes.PassEndWorkNextOne, arguments: {
      "bean": entity,
      "lotEntity": state.lotEntity
    });
  }



}
